/*
 *         Copyright (c) KUBOTA Corporation and HUDSON SOFT,
 *                  1994, 1995 All Rights Reserved
 *
 *  This software comprises unpublished confidential information of
 *  KUBOTA Corp. and HUDSON SOFT. It may not be used, copied or made 
 *  available to anyone, except in accordance with the license under
 *  which it is furnished.
 */
static char SccsId[] = "@(#)samp1.c	1.9	9/19/95";
#include <farl.h>
#include <agl.h>
#define OBJNum		27

unsigned int cube[] = {
#include "cubestp.h"
};

void
main()
{
     int		i, j;
     Material	mt1;
     object	o[OBJNum];
     fix187	otrans[OBJNum][3] = {
	  0x40,   0x40,   0x40,	/* ( 1, 1, 1) */
	  0x0,    0x40,   0x40,	/* ( 0, 1, 1) */
	  0xffc0, 0x40,   0x40,	/* (-1, 1, 1) */
	  0xffc0, 0x0,    0x40,	/* (-1, 0, 1) */
	  0xffc0, 0xffc0, 0x40,	/* (-1,-1, 1) */
	  0x0,    0xffc0, 0x40,	/* ( 0,-1, 1) */
	  0x40,   0xffc0, 0x40,	/* ( 1,-1, 1) */
	  0x40,   0x0,    0x40,	/* ( 1, 0, 1) */
	  0x0,    0x0,    0x40,	/* ( 0, 0, 1) */

	  0x40,   0x40,   0x0,	/* ( 1, 1, 0) */
	  0x0,    0x40,   0x0,	/* ( 0, 1, 0) */
	  0xffc0, 0x40,   0x0,	/* (-1, 1, 0) */
	  0xffc0, 0x0,    0x0,	/* (-1, 0, 0) */
	  0xffc0, 0xffc0, 0x0,	/* (-1,-1, 0) */
	  0x0,    0xffc0, 0x0,	/* ( 0,-1, 0) */
	  0x40,   0xffc0, 0x0,	/* ( 1,-1, 0) */
	  0x40,   0x0,    0x0,	/* ( 1, 0, 0) */
	  0x0,    0x0,    0x0,	/* ( 0, 0, 0) */

	  0x40,   0x40,   0xffc0, /* ( 1, 1,-1) */
	  0x0,    0x40,   0xffc0, /* ( 0, 1,-1) */
	  0xffc0, 0x40,   0xffc0, /* (-1, 1,-1) */
	  0xffc0, 0x0,    0xffc0, /* (-1, 0,-1) */
	  0xffc0, 0xffc0, 0xffc0, /* (-1,-1,-1) */
	  0x0,    0xffc0, 0xffc0, /* ( 0,-1,-1) */
	  0x40,   0xffc0, 0xffc0, /* ( 1,-1,-1) */
	  0x40,   0x0,    0xffc0, /* ( 1, 0,-1) */
	  0x0,    0x0,    0xffc0, /* ( 0, 0,-1) */
     };

     FX73init();
     FX73_cmap_i6c3();
     AGLInit();

#if 1
     /* Hidden Clear */
     FarlSetMemReg(FARL_DISPLAY_CONTROL_REG,
		   FARL_DISPLAY_CONTROL_BCM0 | FARL_DISPLAY_CONTROL_HCE);
     FarlSetPEMaskReg(0x3fff);
     FarlSetPEClearMaskReg(0x3fff);
     FarlSetPEClearColorReg(0x807);
     /**/
#endif

     FarlSetPEICMaskReg(FARL_ICMASK_I6C3);
     FarlSetTEControlReg(FARL_TE_LTEN|FARL_TE_ICM| /*FARL_TE_SPEN|*/FARL_TE_BCE);
     FarlValidateSwap();

     for (i = 0; i < OBJNum; i++) {
	  o[i].geometryTop    = cube;
	  o[i].geometryLength = sizeof(cube)/sizeof(int);
	  o[i].material = NULL;
     }

     mt1.ambient   = 0x1000;
     mt1.diffuse  = 0x3fff;
     mt1.specular = 0x3fff;
     AGLSetMaterial(&mt1, 1);

     o[0].material = &mt1;

     for (i = 0 ;; i += 10) {
	  for (j = 0; j < OBJNum; j++) {
	       AGLResetObj(&(o[j]));
	       AGLScaleObj(&(o[j]), 0x60, 0x60, 0x60);
	       AGLTranslateObj(&(o[j]), otrans[j][0], otrans[j][1], otrans[j][2]);
	       AGLRotateObjZ(&(o[j]), (i * (j/9 + 1))%3600);
	  }

	  AGLResetCamera();
	  AGLRotateCameraY((i*2)%3600);
	  AGLRotateCameraX((i*3)%3600);
	  AGLTranslateCamera(0x0, 0x0, 0xa0);
	  AGLPerspectiveCamera(0xff9a);

	  for (j = 0; j < OBJNum; j++){
	       AGLFixPutObj(&(o[j]));
	  }

	  AGLDrawLightVector(AGL_LIGHT0, 0x805);
	  AGLShot();
     }
     return;
}
